<?php

namespace app\admin\controller;

use app\BaseController;
use app\app\model\ProjectTxglConfigModel;
use app\Request;


class ProjectTxglConfig extends BaseController
{
    public function list()
    {
        $txgl_type = input('txgl_type','');
        $page_size = input('pageSize', '20');

        $where = [];
        if ($txgl_type) {
            $where[] = ['txgl_type', '=', $txgl_type];
        }

        $list = ProjectTxglConfigModel::where($where)->paginate([
            'list_rows'=> $page_size,
            'var_page' => 'pageNum',
        ]);
        $this->success('success', $list);
    }

    public function add(Request $request)
    {
        $data = $request->param();
        $model = new ProjectTxglConfigModel();
        $data['oper_time'] = date('Y-m-d H:i:s', time());
        $result = $model->save($data);
        if ($result !== false) {
            $this->success('添加成功!');
        } else {
            $this->error("保存失败！");
        }
    }

    public function update(Request $request)
    {
        $data = $request->param();
        $id = $request->param('id', 0, 'intval');
        $result = ProjectTxglConfigModel::strict(false)->where('id', $id)->update($data);
        if ($result !== false) {
            $this->success("保存成功！");
        } else {
            $this->error("保存失败！");
        }
    }


    public function delete(Request $request)
    {
        $data = $request->param();
        $ids = $data['ids'];
        ProjectTxglConfigModel::destroy(function ($query) use ($ids) {
            $query->where('id', 'in', $ids);
        });
    }
}
